#include "lodging.h"
#include<QPainter>
#include<QTimer>
#include"gamepanel.h"
Lodging::Lodging(QWidget *parent)
    : QWidget{parent}
{
    m_bk.load(":/images/images/loading.png");
    setFixedSize(m_bk.width(),m_bk.height());

    setWindowFlags(Qt::FramelessWindowHint|windowFlags());
    setAttribute(Qt::WA_TranslucentBackground);


    QTimer *timer =new QTimer(this);
    QPixmap pixmap(":/images/images/progress.png");
    connect(timer,&QTimer::timeout,this,[=](){
        m_progress = pixmap.copy(0,0,m_dist,pixmap.height());

        update();
        if(m_dist >= pixmap.width())
        {
            timer->stop();
            timer->deleteLater();
            GamePanel *panel = new GamePanel;
            panel->show();
            close();
        }
        m_dist+=5;
    });

    timer->start(15);
}

void Lodging::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter p(this);
    p.drawPixmap(rect(),m_bk);
    p.drawPixmap(62,417,m_progress.width(),m_progress.height(),m_progress);
}
